import time

from selenium import webdriver

driver=webdriver.Chrome()
# driver=webdriver.Firefox()
driver.get('http:www.baidu.com')
driver.implicitly_wait(5)
driver.find_element_by_id('kw').send_keys('123')
driver.find_element_by_id('su').click()
driver.maximize_window()
time.sleep(3)
driver.find_element_by_partial_link_text('hao123').click()
time.sleep(4)
driver.get_screenshot_as_file('F:/word/temp.png')#截图页面保存到自己电脑地址
print(driver.window_handles)#输出所有的句柄
print(driver.current_window_handle)#输出当前句柄
driver.switch_to.window(driver.window_handles[1])#切换句柄到第二个页面
print(driver.current_window_handle)#输出当前句柄
time.sleep(3)
driver.quit()

